home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / C / MakeIndex < prev    next >
Text File  |  1997-11-20  |  7KB  |  192 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* Clear icon position */
  22. 'nopos' Volume'disk nodd'
  23.  
  24. /* defines and such */
  25.         /* GREP CALL */
  26. GREPCALL = "grep"
  27.         /* GREP HELP CALL */
  28. GREPHELP = "grep -h"
  29.         /* Where's the CUCD index? */
  30. IDXLOC = Volume'CDsupport/CUCD.index'
  31.         /* Where's the finished guide to go to?*/
  32. outfile = Volume'CDsupport/Docs.guide'
  33.         /* Path to MultiView */
  34. MView = Volume'Utilities/MultiView'
  35.         /* Extensions to search for */
  36. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  37.  
  38. if buildidx='Y' then do
  39.     /* NB the column format is important for the sort fuction later */
  40.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  41.     'list' Volume'CUCD/CDROM all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  42.     'list' Volume'CUCD/Demos all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  43.     'list' Volume'CUCD/Games all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  44.     'list' Volume'CUCD/Graphics all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  45.     'list' Volume'CUCD/Magazine all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  46.     'list' Volume'CUCD/Online all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  47.     'list' Volume'CUCD/Previews all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  48.     'list' Volume'CUCD/Programming all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  49.     'list' Volume'CUCD/Readers all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  50.     'list' Volume'CUCD/Sound all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  51.     'list' Volume'CUCD/Utilities all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  52.     end
  53.  
  54. grepfile = "t:grepoutput." || Pragma("i")
  55. agfile = "t:grepguide." || Pragma("i")
  56. CR      = d2c(10)
  57. TAB     = d2c(9)
  58.  
  59. /* setup the output file - we need this first so we can show errors in it */
  60. IF Open(agfp,agfile,'w') = 0 THEN DO
  61.         SAY "Couldn't create amigaguide file ("||agfile||")"
  62.         EXIT 20
  63.         END
  64.  
  65. call writeln(agfp,'@DATABASE "CD docs"')
  66. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  67. call writeln(agfp,'')
  68. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  69. call writeln(agfp,'')
  70.  
  71. /* Put a search button (needs searchguide in the CDs path) */
  72. if SGUIDE='Y' then do
  73. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  74. call writeln(agfp,'')
  75. end
  76.  
  77. SIGNAL ON FAILURE
  78. ADDRESS COMMAND
  79. 'delete >NIL:' grepfile
  80. do until Extensions = ''
  81.     parse var Extensions ext '|' Extensions
  82.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  83.     end
  84. 'rename' grepfile ' to ' grepfile||'.old'
  85. 'sort' grepfile||'.old' grepfile 'colstart 37'
  86. SIGNAL OFF FAILURE
  87.  
  88. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  89.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  90.         END
  91.  
  92. /*************************************************************************
  93. **  Format of Grep output
  94. **  =====================
  95. **
  96. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  97. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  98. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  99. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  100. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  101. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  102. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  103. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  104. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  105. **
  106. ****************************************************************************/
  107.  
  108. line = ReadLn(grepfp)
  109. IF EOF(grepfp) THEN DO
  110.         call close(grepfp)
  111.         say 'No files found'
  112.         exit 10
  113.         END
  114.  
  115.  
  116.         CALL Pragma('W','n')            /* turn off dos requesters */
  117.  
  118. DO WHILE ~EOF(grepfp)
  119.         /* START BY LOOKING FOR FILENAMES */
  120.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  121.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  122.         if right(currentfile,5) ='guide' then
  123.         do
  124.             node='/main'
  125.             action='link "'
  126.         end
  127.         else
  128.         do
  129.             node=''
  130.             action='system "'MView' '
  131.         end
  132.         endif
  133.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  134.         line = ReadLn(grepfp)
  135.                 END
  136.  
  137. call WriteLn(agfp,'@ENDNODE')
  138.  
  139. call Close(grepfp)
  140. call Close(agfp)
  141.  
  142.        CALL Pragma('W','w')            /* turn dos requesters back on */
  143.  
  144. address command
  145. 'copy' agfile outfile
  146. 'delete >NIL:' grepfile
  147. 'delete >NIL:' grepfile||'.old'
  148. 'delete >NIL:' agfile
  149.  
  150. EXIT
  151.  
  152. FAILURE:
  153. ERROR:
  154.         errRC = RC
  155.         CALL Close(grepfp)
  156.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  157.         EXIT
  158.  
  159. /***************************************************/
  160. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  161.  
  162.         ErrorText = arg(1)
  163.         ErrorFile = arg(2)
  164.  
  165.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  166.         call writeln(agfp,ErrorText)
  167.         call writeln(agfp,' ')
  168.  
  169.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  170.                 call writeln(agfp,"Response:")
  171.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  172.                 Open('errorfp',ErrorFile,'r')
  173.                 DO WHILE ~EOF('errorfp')
  174.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  175.                         END
  176.                 call close('errorfp')
  177.                 END
  178.  
  179.         call writeln(agfp,"")
  180.         call writeln(agfp,"Current Path:")
  181.         call writeln(agfp,"    "||Pragma("D"))
  182.         call writeln(agfp,'@ENDNODE')
  183.  
  184.         call close(agfp)
  185.  
  186.         IF Exists(grepfile) THEN Delete(grepfile)
  187.         Delete(agfile)
  188.  
  189.         EXIT 20
  190. RETURN
  191.  
  192.